unit Con_Vmoeda;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DbTables, Formulario_Padrao_Consulta, Grids, DBGrids, StdCtrls,
  Buttons, ExtCtrls, TFlatButtonUnit;

type
  TFrmCon_VMoeda = class(TFrmConsulta)
    Label1: TLabel;
    dbgVmoeda: TDBGrid;
    btnGravar: TFlatButton;
    procedure BtnFecharClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure btnGravarClick(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Moe_Codigo: string;
    VMoe_Data: TDateTime;
    Moe_Descricao: string;
  end;

var
  FrmCon_Vmoeda: TFrmCon_Vmoeda;

implementation
uses Dm, Biblio, clsVmoeda, Cad_VMoeda, menu;

{$R *.DFM}

var
  Vmoeda: TVmoeda;
  tds: Tdatasource;
  tq: Tquery;

procedure TFrmCon_VMoeda.BtnFecharClick(Sender: TObject);
begin
  inherited;
  vmoe_data := tq.fieldbyname('vmoe_data').AsDateTime;
  tds.free;
  tq.free;
end;

procedure TFrmCon_VMoeda.FormActivate(Sender: TObject);
begin
  inherited;
  if FileExists(caminho_personal + 'belquimica') then begin
    btnGravar.Visible := False;
  end;
  label1.caption := moe_descricao;
  tds := TDataSource.create(FrmCon_Vmoeda);
  tq := Tquery.create(FrmCon_Vmoeda);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tds.DataSet := tq;
  fazconsulta;
end;

procedure TfrmCon_Vmoeda.FazConsulta;
begin
  Vmoeda := TVmoeda.Create;
  Vmoeda.Consultar(tq, moe_codigo, vmoe_data);
  tq.open;
  Vmoeda.free;
  dbgVmoeda.DataSource := tds;
  dbgVmoeda.Refresh;
end;

procedure TFrmCon_VMoeda.btnGravarClick(Sender: TObject);
var
  f1: TfrmCad_Vmoeda;
begin
  inherited;
  f1 := TfrmCad_Vmoeda.Create(self);
  f1.btnC_Vmoeda.Visible := False;
  f1.ShowModal;
  f1.free;
  fazconsulta;
end;

end.
